package com.manage;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Group {
    private int id;
    private String name;
    private List<Student> members;
    private double score;
    
    public Group(int id, String name) {
        this.id = id;
        this.name = name;
        this.members = new ArrayList<>();
        this.score = 0.0;
    }

    // 小组管理方法
    public void addMember(Student student) {
        members.add(student);
    }

    public void removeMember(Student student) {
        members.remove(student);
    }

    // 随机选择组员
    public Student getRandomMember() {
        if (members.isEmpty()) return null;
        Random random = new Random();
        return members.get(random.nextInt(members.size()));
    }

    // 评分方法
    public void setScore(double score) {
        this.score = score;
    }

    // Getters and Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Student> getMembers() {
        return members;
    }

    public double getScore() {
        return score;
    }

    /**
     * 重写toString方法，用于在JList中显示小组名称
     * @return 小组名称
     */
    @Override
    public String toString() {
        return name;
    }
}
